package com.opal.system.controller;

import com.opal.modules.costReportForm.entity.AcMail;
import com.opal.modules.costReportForm.entity.ActivitiUser;
import com.opal.modules.costReportForm.entity.CostReport;
import com.opal.system.entity.table.activiti.ActHiProcinst;
import com.opal.system.entity.table.activiti.ActHiTaskinst;
import com.opal.system.service.ActivitiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 后台管理流程接口
 */
@RequestMapping("system/activiti")
@Controller
public class ActivitiController {

    @Autowired
    private ActivitiService activitiService;

    /**
     * 根据任务Id直接完成任务(财务都不肯点)
     * @param taskId
     * @return
     */
    @RequestMapping("completeTheTaskDirectly")
    @ResponseBody
    public Object completeTheTaskDirectly(String taskId){
        return activitiService.completeTheTaskDirectlyService(taskId);
    }

    /**
     * 结束流程
     * @param procInstId 实例id
     * @param cause 结束流程原因
     * @return
     */
    @RequestMapping("deleteProcess")
    @ResponseBody
    public Object deleteProcess(String procInstId,String cause){
        return activitiService.deleteProcessService(procInstId,cause);
    }

    /**
     *  根据条件获取成本报告的任务
     * @param costReport    成本报告对象
     * @param isEnd  sql 语句    is not null 和 is null  刷选任务的完成
     * @return
     */
    @RequestMapping("queryActHiTaskinstByCostReport")
    @ResponseBody
    public Object queryActHiTaskinstByCostReport(CostReport costReport,String isEnd){
       return  activitiService.queryActHiTaskinstByCostReportService(costReport,isEnd);
    }

    /**
     * 查询activiti实例表
     * @param actHiProcinst
     * @return
     */
    @RequestMapping("queryActHiProcinst")
    @ResponseBody
    public Object queryActHiProcinst(ActHiProcinst actHiProcinst){
        return activitiService.queryActHiProcinstService(actHiProcinst);
    }

    /**
     * 查询历史任务表
     * @param actHiTaskinst
     * @return
     */
    @RequestMapping("queryActHiTaskinst")
    @ResponseBody
    public Object queryActHiTaskinst(ActHiTaskinst actHiTaskinst){
        return activitiService.queryActHiTaskinstService(actHiTaskinst);
    }

    /**
     * 查询流程变量
     * @param procInstId
     * @return
     */
    @RequestMapping("selectVariable")
    @ResponseBody
    public Object selectVariable(String procInstId){
        Object o = activitiService.selectVariableService(procInstId);
        return o;
    }

    /**
     * 修改流程变量
     * @param procInstId
     * @param acMail
     * @param activitiUser
     * @return
     */
    @RequestMapping("updateVariable")
    @ResponseBody
    public Object updateVariable(String procInstId, AcMail acMail, ActivitiUser activitiUser,Double grossMarginRate,String saleType){

        return activitiService.updateVariableService(procInstId,acMail,activitiUser,grossMarginRate,saleType);
    }

    /**
     * 获取所有用户刷新layui用户下拉列表
     * @return
     */
    @RequestMapping("getUser")
    @ResponseBody
    public Object getUser(){
        return activitiService.getUserService();
    }

    @RequestMapping("{page}")
    public String skipPage(@PathVariable("page") String page){
        return  "system/activiti/"+page;
    }
}
